package snake;

import java.util.ArrayList;
import java.util.List;

public class Snake
{

	private SnakePart head;
	private SnakePart tail;
	private int size;
	private List<SnakePart> eatenParts;
	
	public Snake()
	{
		head=null;
		tail=null;
		size=0;
		setEatenParts(new ArrayList<SnakePart>());
	}

	public SnakePart getHead()
	{
		return head;
	}

	public void setHead(SnakePart head)
	{
		this.head = head;
	}
	
	public void addPart(SnakePart newPart)
	{
		if(head==null && tail==null)
		{
			head=newPart;
			head.next=null;
			tail=newPart;
			tail.next=null;
		}
		else
		{
			SnakePart lastHead=head;
			head=newPart;
			lastHead.setNext(newPart);
			head.next=null;
			size++;
		}
	}
	
	public SnakePart removePart()
	{
	
		if(size!=0)
		{
			SnakePart newTail=tail.next;
			tail.next=null;
			SnakePart oldTail=tail;
			tail=newTail;
			size--;
			return oldTail;		
		}
		else
		{
			return null;
		}
	}

	public int getSize()
	{
		return size;
	}
	
	public SnakePart getTail()
	{
		return tail;
	}

	public List<SnakePart> getEatenParts()
	{
		return eatenParts;
	}

	public void setEatenParts(List<SnakePart> eatenParts)
	{
		this.eatenParts = eatenParts;
	}


}
